package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.pojo.SubDicRequest;
import cn.stylefeng.guns.modular.business.service.SubDicService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 检索词典控制器
 *
 * @author zhangyaowen
 * @date 2021/08/30 10:17
 */
@RestController
@ApiResource(name = "检索词典")
public class SubDicController {

    @Resource
    private SubDicService subDicService;

    /**
     * 添加
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @PostResource(name = "添加", path = "/subDic/add")
    public ResponseData add(@RequestBody @Validated(SubDicRequest.add.class) SubDicRequest subDicRequest) {
        subDicService.add(subDicRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @PostResource(name = "删除", path = "/subDic/delete")
    public ResponseData delete(@RequestBody @Validated(SubDicRequest.delete.class) SubDicRequest subDicRequest) {
        subDicService.del(subDicRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @PostResource(name = "编辑", path = "/subDic/edit")
    public ResponseData edit(@RequestBody @Validated(SubDicRequest.edit.class) SubDicRequest subDicRequest) {
        subDicService.edit(subDicRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @GetResource(name = "查看详情", path = "/subDic/detail")
    public ResponseData detail(@Validated(SubDicRequest.detail.class) SubDicRequest subDicRequest) {
        return new SuccessResponseData(subDicService.detail(subDicRequest));
    }

    /**
     * 获取列表
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @GetResource(name = "获取列表", path = "/subDic/list")
    public ResponseData list(SubDicRequest subDicRequest) {
        return new SuccessResponseData(subDicService.findList(subDicRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhangyaowen
     * @date 2021/08/30 10:17
     */
    @GetResource(name = "分页查询", path = "/subDic/page")
    public ResponseData page(SubDicRequest subDicRequest) {
        return new SuccessResponseData(subDicService.findPage(subDicRequest));
    }

}